<?php
class Friends{
var $friends;
var $db;
var $r;
	function Friends(){
				$this->db= new DB();
	}
	
	function Get_friends($LOG)
	{
		$this->db->query("select * 
				from friendship as f 
				where f.id1=(select id from user as a where a.mail=\"".$LOG."\");");
		return $this->row;	
	}
	function Add_friends($LOG,$friend_id)
	{
		$this->db->query("INSERT INTO friendship (id1,id2,accept1,accept2) Values (".$LOG.",".$friend_id.",1,0);");
				
		$this->db->query("INSERT INTO friendship (id1,id2,accept1,accept2)
			Values (".$friend_id.",".$LOG.",0,1);");
	}
	function Accept_friendship($LOG,$friend_id)// LOG accept request of $friend_id
	{
		$this->db->query("UPDATE friendship SET accept1=1 where id1=".$LOG." and id2=".$friend_id.";");
		$this->db->query("UPDATE friendship SET accept2=1 where id2=".$LOG." and id1=".$friend_id.";");
	}
	
		function Ignore_friendship($LOG,$friend_id)// LOG ignore request of $friend_id
	{
		$this->db->query("DELETE FROM friendship WHERE id1=".$friend_id." and id2=".$LOG.";");
		$this->db->query("DELETE FROM friendship WHERE id2=".$friend_id." and id1=".$LOG.";");
	}
	
			function Delete_Friend($LOG,$friend_id)// LOG delete friend request of $friend_id
	{
		$this->db->query("DELETE FROM friendship WHERE id1=".$friend_id." and id2=".$LOG.";");
		$this->db->query("DELETE FROM friendship WHERE id2=".$friend_id." and id1=".$LOG.";");
	}
	
}
?>
